<template>
  <div class="collect-page">
    <van-nav-bar fixed title="我的收藏" />
    <van-list
      v-model="loading"
      :finished="finished"
      finished-text="没有更多了"
      @load="onLoad"
    >
      <ArticleItem
        v-for="item in list"
        :item="item"
        :key="item.id"
      ></ArticleItem>
    </van-list>
  </div>
</template>

<script>
import { getArticlesCollect } from '@/api/article'
export default {
  name: 'CollectPage',
  data () {
    return {
      list: [], // 数据数组
      page: 1,
      loading: false, // 控制加载状态
      finished: false // 控制是否全部加载完成
    }
  },
  methods: {
    async onLoad () {
      // 1. 发请求
      const res = await getArticlesCollect({
        page: this.page
      })
      this.list.push(...res.data.rows)

      // 2. 修改加载状态
      this.loading = false

      // 3. 让当前页码++
      this.page++

      // 4. 判断是否全部加载完毕了
      if (this.page > res.data.pageTotal) {
        this.finished = true
      }
    }
  }
}
</script>

<style lang="less" scoped>
.collect-page{
  margin-bottom: 50px;
  margin-top: 44px;
}
</style>
